import java.util.Scanner;

/**
 * ClassName: Java07_Object
 * Package: PACKAGE_NAME
 * DESCRIPTION:选择排序
 *
 * @Author 程翎钥
 * @Create 2024/3/30 11:00
 * @Version 1.0
 */
public class Java07_Object {
    public static void main(String[] args) {
        int[] a = {1,2,3,4,5,6};
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要查找的数:");
        int s= scan.nextInt();
        int left = 0;
        int right = a.length-1;
        int flag=1;
        while(left<=right){
            int middle = left + (right-left)/2;
            if(a[middle] >s){
                right = middle-1;
            }
            else if(a[middle] < s){
                left = middle+1;
            }
            else{
                System.out.println("找到了，其下标为" + middle);
                flag=0;
                break;
            }
        }
        if(flag == 1)
            System.out.println("很遗憾，没找到");
        scan.close();
    }
}
